/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author karenAndy
 */
import java.util.Scanner;
import java.util.ArrayList;
import java.util.LinkedList;

public class Prompt {

    public static void main(String[] args) throws ExceptionErrorInStatement {
        Prompt();
    }

    public static void Prompt() throws ExceptionErrorInStatement {
        String inputInst;
        Scanner input = new Scanner(System.in);
        LinkedList lista = new LinkedList();
        String show;
        show="";
        show+="         /////                //////             //////   ////////////////    /////////////////\n";
        show+="       //    //               //////             //////  //////////////////   ///////////////////\n";
        show+="      /       //              //////             //////  /////                //////           ///\n";
        show+="              //              //////             //////     ////              //////           ///\n";
        show+="            ////              //////             //////        ////           ///////////////////\n";
        show+="          //   //             //////             //////           ////        /////////////////\n";
        show+="        //     //             //////             //////              ////     //////\n";
        show+="      //        //     /      //////             //////                /////  //////\n";
        show+="    ///         ///   //      ////////////////// //////  //////////////////   //////\n";
        show+=" ////            /////        ////////////////// //////   ////////////////    //////\n";

        System.out.println(show);
        System.out.println("Copyright: José García, Julio Chicas, Ernesto Rodríguez, Karen Tojín");
        System.out.println();
        do {
            System.out.print(">> ");
            inputInst = input.nextLine();

            try {
                lista = (LinkedList) parser.parseList(EvaluarOperandos(EvaluarInput(inputInst)));
                System.out.println(lista.toString());
            } catch (ExceptionErrorInStatement e) {
                System.out.println("Error. Wrong imput format. 1");
            } catch (Exception e) {
                System.out.println("Error. Wrong imput format.");
            }

        } while (inputInst.compareTo("exit") != 0);
        
    }

    public static void ShowInstruction(String instruction, int ip) {

        System.out.println("[" + ip + 1 + "]" + instruction);

    }

    public static String EvaluarInput(String instruction) throws ExceptionErrorInStatement {

        //int numLinea=0;

        boolean correcto = false;
        int cont = 0;
        String newString = "";
        char car = ' ';
        for (int i=0; (i<instruction.length() || !(correcto && cont == 0)); i++) {
            car = instruction.charAt(i);
            if (car == '(') {
                correcto = true;
                newString += " ( ";
                cont++;
            }
            if (car == ')') {
                newString += " ) ";
                cont--;
            }
            if (cont != 0 && car != ')' && car != '(') {
                newString += instruction.charAt(i);
            }
        }

        if (correcto && cont == 0) {
            return newString;
        } else {
            throw new ExceptionErrorInStatement();
        }
    }

    public static String EvaluarOperandos(String prevList){
        char ops=' ';
        ArrayList operandos = new ArrayList();
        ArrayList temp = new ArrayList();
        String defList="";

        for(int j=0; j<prevList.length(); j++){
            temp.add(prevList.charAt(j));
        }
        for(int i=0; i<temp.size(); i++){
            ops = (Character)(temp.get(i));
            if(ops=='+' || ops=='-' || ops=='*' || ops=='/'){
                temp.remove(i);
                operandos.add(ops);
            }
            defList+=temp.get(i);
        }

        System.out.println(defList);
        for(int k=0; k<temp.size(); k++){
            System.out.print(temp.get(k)+"");
        }
        System.out.println();
        for(int l=0; l<operandos.size(); l++){
            System.out.print(operandos.get(l)+"");
        }
        System.out.println();
        return prevList;
    }
}
